﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAL;

namespace BLL
{
   public class ClsTinhBus

    {
        public ClsTinhInfo Info = new ClsTinhInfo();
        public DataTable SelectOne()
        {

            ClsDataAccess oConnection = new ClsDataAccess();
            string strSql = @"SELECT * FROM TinhTP WHERE MaTinh='"+Info.Ma+"'";
            if (oConnection.ExecuteSelect(strSql)) return oConnection.ODataTable;
            else return null;
        }
        public DataTable SelectAll()
        {
          
            ClsDataAccess oConnection = new ClsDataAccess();
            string strSql = @"SELECT * FROM TinhTP";

            if (oConnection.ExecuteSelect(strSql))
            {
                oConnection.ODataTable.Columns.Add("STT");
                int i = 0;
                foreach (DataRow oDRow in oConnection.ODataTable.Rows)
                {
                    oDRow["STT"] = (i + 1);
                    i++;
                }
                return oConnection.ODataTable;
            }
            else return null;
        }
        public bool Them()
        {
            string strSql = "EXECUTE InsertTinhTP '" + Info.Ma + "', N'" + Info.Ten + "', N'" + Info.ID + "','"+Info.SoGK+ "','"+Info.xMax+ "','"+Info.yMax+ "','"+Info.xMin+ "','"+Info.yMin+"'";
            ClsDataAccess oConnection = new ClsDataAccess();
            return (oConnection.ExecuteStoredProcedure(strSql));
        }

        public bool Sua()
        {
            string strSql = "EXECUTE UpdateTinhTP '" + Info.Ma + "', N'" + Info.Ten + "', N'" + Info.ID + "','" + Info.xMax + "','" + Info.yMax + "','" + Info.xMin + "','" + Info.yMin + "'";
            ClsDataAccess oConnection = new ClsDataAccess();
            return (oConnection.ExecuteStoredProcedure(strSql));
        }
        public bool SuaSoGK()
        {
            string strSql = @"UPDATE TinhTP SET " +
                                "SoGK='" + Info.SoGK + "'WHERE MaTinh='" + Info.Ma + "'";
            ClsDataAccess oConnection = new ClsDataAccess();
            return (oConnection.ExecuteStoredProcedure(strSql));
        }

        public bool Xoa()
        {
            string strSql = "EXECUTE DeleteTinhTP'" + Info.Ma + "'";
            ClsDataAccess oConnection = new ClsDataAccess();
            return (oConnection.ExecuteStoredProcedure(strSql));

        }
    }
}
